import requests
import time
import os
url = "http://124.70.96.248:8080/upload"

# 下载图片
# with open("test_img_urls.txt", "r") as f:
#     for url in f.readlines():
#         url = url.strip()
#         data = requests.get(url)
        
#         local = open("./img/temp/" + url[-18:], "wb")
#         print('save ',url[-18:])
#         local.write(data.content)
#         local.close()
#         time.sleep(0.5)
        
        
# 上传图片
for file in os.listdir('./img/temp'):
    file_path = os.path.join('./img/temp', file)
    print(file_path)
    with open(file_path, 'rb') as data:
        files=[ ('crop_file',(file,data,'image/jpeg')) ]
        response = requests.request("POST", url, headers={
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
        }, data={}, files=files)
        print(response.text)
    time.sleep(1)